convert from readFileStrict
authorJoey Hess <joeyh@joeyh.name>
Wed, 22 Jan 2025 18:43:37 +0000 (14:43 -0400)
committerJoey Hess <joeyh@joeyh.name>
Wed, 22 Jan 2025 18:49:31 +0000 (14:49 -0400)
More of these still to convert, but need to be careful of newline
translation.

Annex/AdjustedBranch.hs
Build/Version.hs
Upgrade/V1.hs

index 4eafcadfe2b5275f8e09a47c3acebd70ce24028f..5d5458fa825ff6ace506e707ad474ebeec29fbb3 100644 (file)
@@ -70,6 +70,7 @@ import Logs.View (is_branchView)
 import Logs.AdjustedBranchUpdate
 import Utility.FileMode
 import qualified Utility.RawFilePath as R
+import qualified Utility.FileIO as F
 
 import Data.Time.Clock.POSIX
 import qualified Data.Map as M
@@ -268,7 +269,7 @@ updateAdjustedBranch adj (AdjBranch currbranch) origbranch
                        -- origbranch.
                        _ <- propigateAdjustedCommits' True origbranch adj commitlck
                        
-                       origheadfile <- inRepo $ readFileStrict . fromRawFilePath . Git.Ref.headFile
+                       origheadfile <- inRepo $ F.readFile' . toOsPath . Git.Ref.headFile
                        origheadsha <- inRepo (Git.Ref.sha currbranch)
                        
                        b <- adjustBranch adj origbranch
@@ -280,8 +281,8 @@ updateAdjustedBranch adj (AdjBranch currbranch) origbranch
                        newheadfile <- case origheadsha of
                                Just s -> do
                                        inRepo $ \r -> do
-                                               let newheadfile = fromRef s
-                                               writeFile (fromRawFilePath (Git.Ref.headFile r)) newheadfile
+                                               let newheadfile = fromRef' s
+                                               F.writeFile' (toOsPath (Git.Ref.headFile r)) newheadfile
                                                return (Just newheadfile)
                                _ -> return Nothing
        
@@ -295,9 +296,9 @@ updateAdjustedBranch adj (AdjBranch currbranch) origbranch
                unless ok $ case newheadfile of
                        Nothing -> noop
                        Just v -> preventCommits $ \_commitlck -> inRepo $ \r -> do
-                               v' <- readFileStrict (fromRawFilePath (Git.Ref.headFile r))
+                               v' <- F.readFile' (toOsPath (Git.Ref.headFile r))
                                when (v == v') $
-                                       writeFile (fromRawFilePath (Git.Ref.headFile r)) origheadfile
+                                       F.writeFile' (toOsPath (Git.Ref.headFile r)) origheadfile
 
                return ok
        | otherwise = preventCommits $ \commitlck -> do
index 0d95dc7b266069ddbea32949876d1a025ecc1c38..e3b905919d06c536eb427dda38ac56f51e90ede7 100644 (file)
@@ -1,6 +1,6 @@
 {- Package version determination. -}
 
-{-# LANGUAGE LambdaCase #-}
+{-# LANGUAGE LambdaCase, OverloadedStrings #-}
 {-# OPTIONS_GHC -fno-warn-tabs #-}
 
 module Build.Version where
@@ -14,7 +14,9 @@ import Prelude
 
 import Utility.Monad
 import Utility.Exception
-import Utility.Misc
+import Utility.OsPath
+import Utility.FileSystemEncoding
+import qualified Utility.FileIO as F
 
 type Version = String
 
@@ -56,11 +58,11 @@ getChangelogVersion = do
        middle = drop 1 . init
 
 writeVersion :: Version -> IO ()
-writeVersion ver = catchMaybeIO (readFileStrict f) >>= \case
+writeVersion ver = catchMaybeIO (F.readFile' f) >>= \case
        Just s | s == body -> return ()
-       _ -> writeFile f body
+       _ -> F.writeFile' f body
   where
-       body = unlines $ concat
+       body = encodeBS $ unlines $ concat
                [ header
                , ["packageversion :: String"]
                , ["packageversion = \"" ++ ver ++ "\""]
@@ -71,4 +73,4 @@ writeVersion ver = catchMaybeIO (readFileStrict f) >>= \case
                , ""
                ]
        footer = []
-       f = "Build/Version"
+       f = toOsPath "Build/Version"
index b1e0d83c95a2d47335ee5c78167deb4600dcf1a1..5540844a706919b286882c7f79155897d6753286 100644 (file)
@@ -204,7 +204,7 @@ writeLog1 file ls = viaTmp F.writeFile
 
 readLog1 :: FilePath -> IO [LogLine]
 readLog1 file = catchDefaultIO [] $
-       parseLog . encodeBL <$> readFileStrict file
+       parseLog <$> F.readFile (toOsPath (toRawFilePath file))
 
 lookupKey1 :: FilePath -> Annex (Maybe (Key, Backend))
 lookupKey1 file = do